package com.tegtech.api.monitor.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.tegtech.api.monitor.service.ISysOperLogService;
import com.tegtech.common.domain.Result;
import com.tegtech.core.controller.BaseController;
import com.tegtech.core.page.PageResult;
import com.tegtech.starter.log.annotation.Log;
import com.tegtech.starter.log.domain.SysOperLog;
import com.tegtech.starter.log.enums.BusinessType;

/**
 * 操作日志记录
 * 
 * @author Jun
 */
@RestController
@RequestMapping("/monitor/operlog")
public class SysOperlogController extends BaseController {
	
	@Autowired
	private ISysOperLogService operLogService;

	@PreAuthorize("@ss.hasPermi('monitor:operlog:list')")
	@GetMapping("/list")
	public PageResult list(SysOperLog operLog) {
		return buildPageResult(() -> operLogService.selectOperLogList(operLog));
	}

	@Log(title = "操作日志", businessType = BusinessType.EXPORT)
	@PreAuthorize("@ss.hasPermi('monitor:operlog:export')")
	@GetMapping("/export")
	public void export(SysOperLog operLog) {
		List<SysOperLog> list = operLogService.selectOperLogList(operLog);
		exportExcel("操作日志", SysOperLog.class, list);
	}

	@PreAuthorize("@ss.hasPermi('monitor:operlog:remove')")
	@DeleteMapping("/{operIds}")
	public Result remove(@PathVariable Long[] operIds) {
		return toResult(operLogService.deleteOperLogByIds(operIds));
	}

	@Log(title = "操作日志", businessType = BusinessType.CLEAN)
	@PreAuthorize("@ss.hasPermi('monitor:operlog:remove')")
	@DeleteMapping("/clean")
	public Result clean() {
		operLogService.cleanOperLog();
		return Result.ok();
	}
}
